//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hecai.scanning.handler;

import java.util.concurrent.LinkedBlockingQueue;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ScannerHandler extends IoHandlerAdapter {
    private static final Logger log = LoggerFactory.getLogger(ScannerHandler.class);
    public static final String KEY_SESSION_COMMNAME = "KEY_SESSION_COMMNAME";
    private static LinkedBlockingQueue<String> ticketIDQueue = new LinkedBlockingQueue();

    public ScannerHandler() {
    }

    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        log.error("exception occurs. session : {}, cause : {}", session, cause);
    }

    public void messageReceived(IoSession session, Object message) throws Exception {
        IoBuffer recvMsg = (IoBuffer)message;
        String commName = (String)session.getAttribute("KEY_SESSION_COMMNAME");
        String ticketIDs = new String(recvMsg.array(), "UTF-8");
        ticketIDQueue.put(ticketIDs);
        log.info("Receive the ticketID : {}, commName : {}", ticketIDs, commName);
    }

    public static LinkedBlockingQueue<String> getTicketIDQueue() {
        return ticketIDQueue;
    }
}
